package org.huangrui.algorithm;

/**
 * @Author hr
 * @Create 2025-11-03 10:59
 * 左右指针-杀
 * 344. 反转字符串
 * https://leetcode.cn/problems/reverse-string/
 * <p>
 * //结果比目标，小了要变大，左针右移+
 * //结果比目标，大了要变小，右针左移-
 **/
public class T021LeetCode344 {
    public void reverseString(char[] s) {
        // 一左一右两个指针相向而行
        // 结果比目标，小了要变大，左针右移+
        // 结果比目标，大了要变小，右针左移-

        int left = 0;// 左指针
        int right = s.length - 1; // 右指针
        while (left < right){
            //1 先交换
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            //2 移动指针
            left++;
            right--;
        }
        System.out.println(s);
    }

    public static void main(String[] args) {
        // char[] s = new char[]{'h','e','l','l','o'};
        // ["H","a","n","n","a","h"]
        char[] s = new char[]{'H','a','n','m','o','h'};
        new T021LeetCode344().reverseString(s);
    }
}
